package com.assignwork.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 二级配工(AssignWork)VO
 * @since 2024-02-20 15:45:03
 */
@Data
@ApiModel(value = "AssignWorkVO", description = "二级配工")
public class AssignWorkVO  {

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "作业线ID")
    private Long lineId;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "昼夜计划ID")
    private Long planId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long shipId;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "配工ID")
    private Long arrangeId;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "作业区域ID")
    private Long workAreaId;

    @ApiModelProperty(value = "作业类型")
    private String workType;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "所属单位")
    private Long belongToId;

    private String belongToName;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "队")
    private Long teamId;

    private String teamName;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "组")
    private Long groupId;

    private String groupName;

    @ApiModelProperty(value = "在册人员")
    private Integer payrollNumber;

    @ApiModelProperty(value = "出勤人数")
    private Integer attendanceNumber;

    @ApiModelProperty(value = "缺勤人数")
    private Integer absenteeismNumber;

    @ApiModelProperty(value = "实际配工人数")
    private Integer workerNumber;

    private String shiftKey;

    @JsonFormat(pattern = DateUtil.PATTERN_DATE)
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATE)
    private LocalDate planDate;

    private String timeSpace;

    private List<AssignWorkInfoVO> workInfo;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long updateUser;

    private String sign;

    public boolean isLoader() {
        return "LOADER_LAND".equals(workType) || "LOADER_SHIP".equals(workType);
    }

    public Map<String, List<AssignWorkInfoVO>> getMapWorkInfo() {
        if (Func.isNotEmpty(workInfo)) {
            return workInfo.stream().filter(i -> i.getArrangeInfoId() != null).collect(Collectors.groupingBy(i -> i.getArrangeInfoId().toString()));
        }
        return null;
    }
}

